home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / dMatrix.h < prev    next >
C/C++ Source or Header  |  1997-03-07  |  8KB  |  270 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_Matrix_int_h)
  24. #define octave_Matrix_int_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include "MArray2.h"
  31. #include "MDiagArray2.h"
  32.  
  33. #include "mx-defs.h"
  34.  
  35. #include "data-conv.h"
  36. #include "mach-info.h"
  37.  
  38. class Matrix : public MArray2<double>
  39. {
  40. friend class ComplexMatrix;
  41. friend class AEPBAL;
  42. friend class CHOL;
  43. friend class GEPBAL;
  44. friend class HESS;
  45. friend class LU;
  46. friend class QR;
  47. friend class QRP;
  48. friend class SCHUR;
  49. friend class SVD;
  50.  
  51. public:
  52.  
  53.   Matrix (void) : MArray2<double> () { }
  54.   Matrix (int r, int c) : MArray2<double> (r, c) { }
  55.   Matrix (int r, int c, double val) : MArray2<double> (r, c, val) { }
  56.   Matrix (const MArray2<double>& a) : MArray2<double> (a) { }
  57.   Matrix (const Matrix& a) : MArray2<double> (a) { }
  58.   Matrix (const RowVector& rv);
  59.   Matrix (const ColumnVector& cv);
  60.   //  Matrix (const MDiagArray2<double>& a) : MArray2<double> (a) { }
  61.   Matrix (const DiagMatrix& a);
  62.  
  63.   Matrix (const charMatrix& a);
  64.  
  65.   Matrix& operator = (const Matrix& a)
  66.     {
  67.       MArray2<double>::operator = (a);
  68.       return *this;
  69.     }
  70.  
  71.   bool operator == (const Matrix& a) const;
  72.   bool operator != (const Matrix& a) const;
  73.  
  74.   // destructive insert/delete/reorder operations
  75.  
  76.   Matrix& insert (const Matrix& a, int r, int c);
  77.   Matrix& insert (const RowVector& a, int r, int c);
  78.   Matrix& insert (const ColumnVector& a, int r, int c);
  79.   Matrix& insert (const DiagMatrix& a, int r, int c);
  80.  
  81.   Matrix& fill (double val);
  82.   Matrix& fill (double val, int r1, int c1, int r2, int c2);
  83.  
  84.   Matrix append (const Matrix& a) const;
  85.   Matrix append (const RowVector& a) const;
  86.   Matrix append (const ColumnVector& a) const;
  87.   Matrix append (const DiagMatrix& a) const;
  88.  
  89.   Matrix stack (const Matrix& a) const;
  90.   Matrix stack (const RowVector& a) const;
  91.   Matrix stack (const ColumnVector& a) const;
  92.   Matrix stack (const DiagMatrix& a) const;
  93.  
  94.   Matrix transpose (void) const;
  95.  
  96.   friend Matrix real (const ComplexMatrix& a);
  97.   friend Matrix imag (const ComplexMatrix& a);
  98.  
  99.   // resize is the destructive equivalent for this one
  100.  
  101.   Matrix extract (int r1, int c1, int r2, int c2) const;
  102.  
  103.   // extract row or column i.
  104.  
  105.   RowVector row (int i) const;
  106.   RowVector row (char *s) const;
  107.  
  108.   ColumnVector column (int i) const;
  109.   ColumnVector column (char *s) const;
  110.  
  111.   Matrix inverse (void) const;
  112.   Matrix inverse (int& info) const;
  113.   Matrix inverse (int& info, double& rcond, int force = 0) const;
  114.  
  115.   Matrix pseudo_inverse (double tol = 0.0);
  116.  
  117.   ComplexMatrix fourier (void) const;
  118.   ComplexMatrix ifourier (void) const;
  119.  
  120.   ComplexMatrix fourier2d (void) const;
  121.   ComplexMatrix ifourier2d (void) const;
  122.  
  123.   DET determinant (void) const;
  124.   DET determinant (int& info) const;
  125.   DET determinant (int& info, double& rcond) const;
  126.  
  127.   Matrix solve (const Matrix& b) const;
  128.   Matrix solve (const Matrix& b, int& info) const;
  129.   Matrix solve (const Matrix& b, int& info, double& rcond) const;
  130.  
  131.   ComplexMatrix solve (const ComplexMatrix& b) const;
  132.   ComplexMatrix solve (const ComplexMatrix& b, int& info) const;
  133.   ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const;
  134.  
  135.   ColumnVector solve (const ColumnVector& b) const;
  136.   ColumnVector solve (const ColumnVector& b, int& info) const;
  137.   ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const;
  138.  
  139.   ComplexColumnVector solve (const ComplexColumnVector& b) const;
  140.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const;
  141.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info,
  142.                  double& rcond) const;
  143.  
  144.   Matrix lssolve (const Matrix& b) const;
  145.   Matrix lssolve (const Matrix& b, int& info) const;
  146.   Matrix lssolve (const Matrix& b, int& info, int& rank) const;
  147.  
  148.   ComplexMatrix lssolve (const ComplexMatrix& b) const;
  149.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const;
  150.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info,
  151.              int& rank) const;
  152.  
  153.   ColumnVector lssolve (const ColumnVector& b) const;
  154.   ColumnVector lssolve (const ColumnVector& b, int& info) const;
  155.   ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const;
  156.  
  157.   ComplexColumnVector lssolve (const ComplexColumnVector& b) const;
  158.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const;
  159.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info,
  160.                    int& rank) const;
  161.  
  162.   Matrix expm (void) const;
  163.  
  164.   Matrix& operator += (const Matrix& a);
  165.   Matrix& operator -= (const Matrix& a);
  166.  
  167.   Matrix& operator += (const DiagMatrix& a);
  168.   Matrix& operator -= (const DiagMatrix& a);
  169.  
  170.   // unary operations
  171.  
  172.   Matrix operator ! (void) const;
  173.  
  174.   // column vector by row vector -> matrix operations
  175.  
  176.   friend Matrix operator * (const ColumnVector& a, const RowVector& b);
  177.  
  178.   // diagonal matrix by scalar -> matrix operations
  179.  
  180.   friend Matrix operator + (const DiagMatrix& a, double s);
  181.   friend Matrix operator - (const DiagMatrix& a, double s);
  182.  
  183.   // scalar by diagonal matrix -> matrix operations
  184.  
  185.   friend Matrix operator + (double s, const DiagMatrix& a);
  186.   friend Matrix operator - (double s, const DiagMatrix& a);
  187.  
  188.   // matrix by diagonal matrix -> matrix operations
  189.  
  190.   friend Matrix operator + (const Matrix& a, const DiagMatrix& b);
  191.   friend Matrix operator - (const Matrix& a, const DiagMatrix& b);
  192.   friend Matrix operator * (const Matrix& a, const DiagMatrix& b);
  193.  
  194.   // diagonal matrix by matrix -> matrix operations
  195.  
  196.   friend Matrix operator + (const DiagMatrix& a, const Matrix& b);
  197.   friend Matrix operator - (const DiagMatrix& a, const Matrix& b);
  198.   friend Matrix operator * (const DiagMatrix& a, const Matrix& b);
  199.  
  200.   // matrix by matrix -> matrix operations
  201.  
  202.   friend Matrix operator * (const Matrix& a, const Matrix& b);
  203.  
  204.   // other operations
  205.  
  206.   Matrix map (d_d_Mapper f) const;
  207.  
  208.   Matrix& apply (d_d_Mapper f);
  209.  
  210.   bool any_element_is_negative (void) const;
  211.   bool any_element_is_inf_or_nan (void) const;
  212.   bool all_elements_are_int_or_inf_or_nan (void) const;
  213.   bool all_integers (double& max_val, double& min_val) const;
  214.   bool too_large_for_float (void) const;
  215.  
  216.   Matrix all (void) const;
  217.   Matrix any (void) const;
  218.  
  219.   Matrix cumprod (void) const;
  220.   Matrix cumsum (void) const;
  221.   Matrix prod (void) const;
  222.   Matrix sum (void) const;
  223.   Matrix sumsq (void) const;
  224.   Matrix abs (void) const;
  225.  
  226.   ColumnVector diag (void) const;
  227.   ColumnVector diag (int k) const;
  228.  
  229.   ColumnVector row_min (void) const;
  230.   ColumnVector row_max (void) const;
  231.  
  232.   ColumnVector row_min (Array<int>& index) const;
  233.   ColumnVector row_max (Array<int>& index) const;
  234.  
  235.   RowVector column_min (void) const;
  236.   RowVector column_max (void) const;
  237.  
  238.   RowVector column_min (Array<int>& index) const;
  239.   RowVector column_max (Array<int>& index) const;
  240.  
  241.   // i/o
  242.  
  243.   friend ostream& operator << (ostream& os, const Matrix& a);
  244.   friend istream& operator >> (istream& is, Matrix& a);
  245.  
  246.   int read (istream& is, int nr, int nc, oct_data_conv::data_type dt,
  247.         int skip, oct_mach_info::float_format flt_fmt);
  248.  
  249.   int write (ostream& os, oct_data_conv::data_type dt, int skip,
  250.          oct_mach_info::float_format flt_fmt);
  251.  
  252. private:
  253.  
  254.   Matrix (double *d, int r, int c) : MArray2<double> (d, r, c) { }
  255. };
  256.  
  257. extern Matrix Givens (double, double);
  258.  
  259. extern Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&);
  260.  
  261. extern ComplexColumnVector Qzval (const Matrix& a, const Matrix& b);
  262.  
  263. #endif
  264.  
  265. /*
  266. ;;; Local Variables: ***
  267. ;;; mode: C++ ***
  268. ;;; End: ***
  269. */
  270.